(:
   Change (to correct) the date values in a display file
   First parameter is the display file
   Second parameter is a positive offset
   Third parameter is a negative offset (offsets are expressed in miliseconds)

Ex :

   task.sh changeTimeOffset.xq zz.xml 4 3 > zz2.xml

   (this adds 4 and subtracts 3)
 :)

declare variable $deltaadd :=
   if ($arguments[2] castable as xs:integer) then
       $arguments[2] cast as xs:integer
   else
       xs:integer(0) ;
declare variable $deltasub :=
   if ($arguments[3] castable as xs:integer) then
       $arguments[3] cast as xs:integer
   else
       xs:integer(0) ;

<display>{
for $it in doc($arguments[1])/display/item
return
<item>{
  for $in in $it/info
  return
    if ($in/@name="time") then
        <info name="time">{
           <time>{
              for $e in $in/time/element()
              return
                if (fn:local-name($e)="date") then
                   <date>{xs:integer(xs:string($e/text())) + $deltaadd - $deltasub}</date>
                else
                   $e
           }</time>
        }</info>
    else
        $in
}</item>
}</display>
